package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ClassManage;
import com.ruoyi.system.service.IClassManageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级一览Controller
 * 
 * @author ruoyi
 * @date 2024-06-05
 */
@RestController
@RequestMapping("/system/manage")
public class ClassManageController extends BaseController
{
    @Autowired
    private IClassManageService classManageService;

    /**
     * 查询班级一览列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassManage classManage)
    {
        startPage();
        List<ClassManage> list = classManageService.selectClassManageList(classManage);
        return getDataTable(list);
    }

    /**
     * 导出班级一览列表
     */
    @PreAuthorize("@ss.hasPermi('system:manage:export')")
    @Log(title = "班级一览", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassManage classManage)
    {
        List<ClassManage> list = classManageService.selectClassManageList(classManage);
        ExcelUtil<ClassManage> util = new ExcelUtil<ClassManage>(ClassManage.class);
        util.exportExcel(response, list, "班级一览数据");
    }

    /**
     * 获取班级一览详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:manage:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Integer classId)
    {
        return success(classManageService.selectClassManageByClassId(classId));
    }

    /**
     * 新增班级一览
     */
    @PreAuthorize("@ss.hasPermi('system:manage:add')")
    @Log(title = "班级一览", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassManage classManage)
    {
        return toAjax(classManageService.insertClassManage(classManage));
    }

    /**
     * 修改班级一览
     */
    @PreAuthorize("@ss.hasPermi('system:manage:edit')")
    @Log(title = "班级一览", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassManage classManage)
    {
        return toAjax(classManageService.updateClassManage(classManage));
    }

    /**
     * 删除班级一览
     */
    @PreAuthorize("@ss.hasPermi('system:manage:remove')")
    @Log(title = "班级一览", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Integer[] classIds)
    {
        return toAjax(classManageService.deleteClassManageByClassIds(classIds));
    }
}
